home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / snip9_91.arc / TREEDIR.C < prev    next >
C/C++ Source or Header  |  1991-09-17  |  2KB  |  57 lines

  1. /*
  2. **  TREEDIR.C - simple recursive directory lister
  3. **
  4. **  public domain demo by Bob Stout
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. #ifdef __ZTC__
  11.  #if __ZTC__ < 0x210    /* ZTC 2.0 and lower...                         */
  12.   #include <mflfiles.h> /*  ...don't do recursive find first/next...    */
  13.   #include <msport.h>   /*   ...so use MFLZT library functions          */
  14.  #else                  /* ZTC 2.1 has MSC look-alike functions         */
  15.   #include <dos.h>
  16.   #define _A_SUBDIR FA_DIREC
  17.  #endif
  18. #elif defined(__TURBOC__)
  19.  #include <dir.h>
  20.  #include <dos.h>
  21.  #define _dos_findfirst(f,a,b) findfirst(f,b,a)
  22.  #define _dos_findnext(b) findnext(b)
  23.  #define find_t ffblk
  24.  #define _A_SUBDIR FA_DIREC
  25.  #define attrib ff_attrib
  26.  #define name ff_name
  27. #else                   /* assume MSC/QC                                */
  28.  #include <dos.h>
  29.  #include <errno.h>
  30. #endif
  31.  
  32. #ifndef SUCCESS
  33.  #define SUCCESS 0
  34. #endif
  35.  
  36. void do_dir(char *path)
  37. {
  38.         char search[67], new[67];
  39.         struct find_t ff;
  40.  
  41.         strcat(strcpy(search, path), "\\*.*");
  42.         if (SUCCESS == _dos_findfirst(search, 0xff, &ff)) do
  43.         {
  44.                 printf("%s\\%s\n", path, ff.name);
  45.                 if (ff.attrib & _A_SUBDIR && '.' != *ff.name)
  46.                 {
  47.                         strcat(strcat(strcpy(new, path), "\\"), ff.name);
  48.                         do_dir(new);
  49.                 }
  50.         } while (SUCCESS == _dos_findnext(&ff));
  51. }
  52.  
  53. main()                  /* simple resursive current directory lister    */
  54. {
  55.         do_dir(".");
  56. }
  57.